<template>
    <div>
        <label for="username">
            账号：
            <input type="text" id="username" v-model="user">
        </label>
        <label for="password">
            密码：
            <input type="text" id="password" v-model="pwd">
        </label>
        <button @click="login">登录</button>
    </div>
</template>

<script>
    import {mapActions} from 'vuex'
    export default {
        name: "login",
        data(){
            return{
                user:'',
                pwd:''
            }
        },
        methods:{
            ...mapActions(['loginUser']),
            login(){
                let obj={user:this.user,pwd:this.pwd}
                this.loginUser(obj).then(res=>{
                    // console.log(res)
                    if(res.code===200){
                        this.$router.push('/index')
                    }else if(res.code===400){
                        alert(res.data.err)
                        this.user= ''
                        this.pwd = ''
                    }
                })
            },

        }
    }
</script>

<style scoped>

</style>